namespace SinaFinance.ChartLibrary.AxisLibrary
{
    using SinaFinanceBaseClassLibrary;
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Media.Imaging;

    public partial class TimeSharingLineAxis : UserControl
    {
        //private bool _contentLoaded;
        private List<TimeSharingPoint> averagePoints;
        private AxisSysTimeSharing axis = new AxisSysTimeSharing();
        private double bottomSpan = 0.0;
        private Color color1 = new Color();
        private Color color2 = new Color();
        private Canvas coverCanvas = new Canvas();
        private string currentStockID = string.Empty;
        private bool isOnload = true;
        private int keyFramesAmount = 20;
        //internal Grid LayoutRoot;
        private double leftSpan = 0.0;
        private List<string> leftYAxisTips = new List<string>();
        private Dictionary<string, List<TimeSharingPoint>> percentPoints;
        private double rightSpan = 0.0;
        private List<string> rightYAxisTips = new List<string>();
        //internal Canvas rootCanvas;
        private List<TimeSharingPoint> timeSharingPoint;
        private double topSpan = 0.0;
        private PointTypeEnum type = PointTypeEnum.TimeSharing;

        public TimeSharingLineAxis()
        {
            this.InitializeComponent();
            base.Loaded += new RoutedEventHandler(this.TimeSharingLineAxis_Loaded);
        }

        public void BeginTimeSharingLineStoryboard()
        {
        }

        //[DebuggerNonUserCode]
        //public void InitializeComponent()
        //{
        //    if (!this._contentLoaded)
        //    {
        //        this._contentLoaded = true;
        //        Application.LoadComponent(this, new Uri("/SinaFinance;component/ChartLibrary/AxisLibrary/TimeSharingLineAxis.xaml", UriKind.Relative));
        //        this.LayoutRoot = (Grid) base.FindName("LayoutRoot");
        //        this.rootCanvas = (Canvas) base.FindName("rootCanvas");
        //    }
        //}

        public void RemoveLine()
        {
            this.axis.RemoveLineObj();
        }

        private void storyboard_CanvasTranslateTransform_Completed(object sender, EventArgs e)
        {
        }

        private void storyboard_CanvasWidth_Completed(object sender, EventArgs e)
        {
            this.rootCanvas.Children.Remove(this.coverCanvas);
        }

        private void TimeSharingLineAxis_Loaded(object sender, RoutedEventArgs e)
        {
            Storyboard storyboard = new Storyboard();
            Storyboard storyboard2 = new Storyboard();
            DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames();
            DoubleAnimationUsingKeyFrames frames2 = new DoubleAnimationUsingKeyFrames();
            List<SplineDoubleKeyFrame> list = new List<SplineDoubleKeyFrame>();
            List<SplineDoubleKeyFrame> list2 = new List<SplineDoubleKeyFrame>();
            LinearGradientBrush brush = new LinearGradientBrush();
            GradientStop stop = new GradientStop();
            GradientStop stop2 = new GradientStop();
            stop.Color = Color.FromArgb(0xff, 0, 0, 0);
            stop.Offset = 0.0;
            stop2.Color = Color.FromArgb(0xff, 0x13, 0x1b, 0x29);
            stop2.Offset = 1.0;
            brush.StartPoint = new Point(0.0, 0.0);
            brush.EndPoint = new Point(0.0, 1.0);
            brush.GradientStops.Add(stop);
            brush.GradientStops.Add(stop2);
            this.rootCanvas.Background = brush;
            Image image = new Image {
                Source = new BitmapImage(new Uri("../../Images/CrossLineCore.png", UriKind.RelativeOrAbsolute))
            };
            if (base.Width <= 0.0)
            {
                base.Width = 600.0;
            }
            if (base.Height <= 0.0)
            {
                base.Height = 400.0;
            }
            TransformGroup group = new TransformGroup();
            ScaleTransform transform = new ScaleTransform();
            SkewTransform transform2 = new SkewTransform();
            RotateTransform transform3 = new RotateTransform();
            TranslateTransform transform4 = new TranslateTransform();
            group.Children.Add(transform);
            group.Children.Add(transform2);
            group.Children.Add(transform3);
            group.Children.Add(transform4);
            this.coverCanvas.RenderTransform = group;
            this.axis.Width = base.Width;
            this.axis.Height = base.Height;
            this.axis.LeftSpan = this.leftSpan;
            this.axis.RightSpan = this.rightSpan;
            this.axis.TimeSharingPoints = this.timeSharingPoint;
            this.axis.AveragePoints = this.averagePoints;
            this.axis.PercentPoints = this.percentPoints;
            this.axis.ParentCanvas = this.rootCanvas;
            this.axis.TopSpan = this.topSpan;
            this.axis.BottomSpan = this.bottomSpan;
            this.axis.LeftYAxisTips = this.leftYAxisTips;
            this.axis.RightYAxisTips = this.rightYAxisTips;
            this.axis.CurrentStockID = this.currentStockID;
            this.axis.CoreImage = image;
            bool isTimeSharingLine = true;
            if (this.type.Equals(PointTypeEnum.Percent))
            {
                this.axis.Color1 = this.color1;
                this.axis.Color2 = this.color2;
                isTimeSharingLine = false;
            }
            this.axis.RenderAxisSys(isTimeSharingLine);
            if (this.isOnload)
            {
                int num;
                SplineDoubleKeyFrame frame;
                this.coverCanvas.Width = this.axis.pointRightTop.X - this.axis.pointLeftTop.X;
                this.coverCanvas.Height = this.axis.pointRightBottom.Y - this.axis.pointRightTop.Y;
                this.coverCanvas.Margin = new Thickness(this.axis.pointLeftTop.X + 1.0, this.axis.pointLeftTop.Y, 0.0, 0.0);
                this.coverCanvas.SetValue(Canvas.ZIndexProperty, 15);
                this.coverCanvas.SetValue(FrameworkElement.NameProperty, "timeSharingCoverCanvas");
                this.coverCanvas.Background = brush;
                if (!this.rootCanvas.Children.Contains(this.coverCanvas))
                {
                    this.rootCanvas.Children.Add(this.coverCanvas);
                }
                base.Resources.Remove("WidthStoryboard");
                base.Resources.Remove("TranslateTransformStoryboard");
                base.Resources.Add("WidthStoryboard", storyboard);
                base.Resources.Add("TranslateTransformStoryboard", storyboard2);
                storyboard.Stop();
                storyboard2.Stop();
                frames.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("(FrameworkElement.Width)", new object[0]));
                frames.SetValue(Storyboard.TargetNameProperty, "timeSharingCoverCanvas");
                frames2.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)", new object[0]));
                frames2.SetValue(Storyboard.TargetNameProperty, "timeSharingCoverCanvas");
                for (num = 0; num < this.keyFramesAmount; num++)
                {
                    frame = new SplineDoubleKeyFrame();
                    frames.KeyFrames.Add(frame);
                    list.Add(frame);
                }
                for (num = 0; num < this.keyFramesAmount; num++)
                {
                    frame = new SplineDoubleKeyFrame();
                    frames2.KeyFrames.Add(frame);
                    list2.Add(frame);
                }
                storyboard.Children.Add(frames);
                storyboard2.Children.Add(frames2);
                double num2 = this.coverCanvas.Width / ((double) this.keyFramesAmount);
                for (num = 0; num < this.keyFramesAmount; num++)
                {
                    list[num].KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds((double) (num * 0.2)));
                    list[num].Value = this.coverCanvas.Width - (num2 * (num + 1));
                    list2[num].KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds((double) (num * 0.2)));
                    list2[num].Value = num2 * (num + 1);
                }
                storyboard.Begin();
                storyboard2.Begin();
            }
        }

        public List<TimeSharingPoint> AveragePoints
        {
            get
            {
                return this.averagePoints;
            }
            set
            {
                this.averagePoints = value;
            }
        }

        public double BottomSpan
        {
            get
            {
                return this.bottomSpan;
            }
            set
            {
                this.bottomSpan = value;
            }
        }

        public Color Color1
        {
            get
            {
                return this.color1;
            }
            set
            {
                this.color1 = value;
            }
        }

        public Color Color2
        {
            get
            {
                return this.color2;
            }
            set
            {
                this.color2 = value;
            }
        }

        public string CurrentStockID
        {
            get
            {
                return this.currentStockID;
            }
            set
            {
                this.currentStockID = value;
            }
        }

        public bool IsOnload
        {
            get
            {
                return this.isOnload;
            }
            set
            {
                this.isOnload = value;
            }
        }

        public double LeftSpan
        {
            get
            {
                return this.leftSpan;
            }
            set
            {
                this.leftSpan = value;
            }
        }

        public List<string> LeftYAxisTips
        {
            get
            {
                return this.leftYAxisTips;
            }
            set
            {
                this.leftYAxisTips = value;
            }
        }

        public Dictionary<string, List<TimeSharingPoint>> PercentPoint
        {
            get
            {
                return this.percentPoints;
            }
            set
            {
                this.percentPoints = value;
            }
        }

        public double RightSpan
        {
            get
            {
                return this.rightSpan;
            }
            set
            {
                this.rightSpan = value;
            }
        }

        public List<string> RightYAxisTips
        {
            get
            {
                return this.rightYAxisTips;
            }
            set
            {
                this.rightYAxisTips = value;
            }
        }

        public List<TimeSharingPoint> TimeSharingPoints
        {
            get
            {
                return this.timeSharingPoint;
            }
            set
            {
                this.timeSharingPoint = value;
            }
        }

        public double TopSpan
        {
            get
            {
                return this.topSpan;
            }
            set
            {
                this.topSpan = value;
            }
        }

        public PointTypeEnum Type
        {
            get
            {
                return this.type;
            }
            set
            {
                this.type = value;
            }
        }
    }
}
